﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Web;

namespace DataAccess
{
    public class Link
    {
        private static string BuildAbsolute(string relativeUrl)
        {
            Uri uri = HttpContext.Current.Request.Url;
            string app = HttpContext.Current.Request.ApplicationPath;
            if (!app.EndsWith("/"))
                app += "/";
            relativeUrl = relativeUrl.TrimStart('/');
            return HttpUtility.UrlPathEncode(String.Format("http://{0}:{1}{2}{3}", uri.Host, uri.Port, app, relativeUrl));
        }
        public static string ToCategory(string categoryID, string page)
        {
            if (page == "1")
                return BuildAbsolute(String.Format("Catalog.aspx?CategoryID={0}", categoryID));
            else
                return BuildAbsolute(String.Format("Catalog.aspx?CategoryID={0}&Page={1}", categoryID, page));
        }

        public static string ToCategory(string categoryID)
        {
            return ToCategory(categoryID, "1");
        }

        public static string ToCatalog(string page)
        {
            if (page == "1")
            {
                return BuildAbsolute("Catalog.aspx");
            }
            else
                return BuildAbsolute(String.Format("Catalog.aspx?Page={0}", page));
        }

        public static string ToCatalog()
        {
            return ToCatalog("1");
        }
        public static string ToProduct(string productID)
        {
            return BuildAbsolute(String.Format("Product.aspx?ProductID={0}", productID));
        }
        public static string ToProductImage(string fileName)
        {
            return BuildAbsolute(String.Format("ProductImage/{0}", fileName));
        }
        public static string ToAddToCart(string productId)
        {
            return BuildAbsolute(String.Format("AddToCart.aspx?ProductID={0}", productId));
        }

        public static string ToSearch(string searchString, string page)
        {
            if (page == "1")
                return BuildAbsolute(String.Format("Search.aspx?Search={0}", searchString));
            return BuildAbsolute(String.Format("Search.aspx?Search={0}&Page={1}", searchString, page));
        }

        public static string ToSearch(string searchString)
        {
            return ToSearch(searchString, "1");
        }

        public static string ToAdminProduct(string page)
        {
            if (page == "1")
                return BuildAbsolute(String.Format("Admin/Product.aspx"));
            return BuildAbsolute(String.Format("Admin/Product.aspx?Page={0}", page));

        }

        public static string ToAdminProduct()
        {
            return ToAdminProduct("1");
        }

        public static string ToCustomerDetails(string page)
        {
            if (page == "1")
                return BuildAbsolute("CustomerDetails.aspx");
            else
                return BuildAbsolute(String.Format("CustomerDetails.aspx?Page={0}", page));
        }

        public static string ToProductWithComment(string productId, string page)
        {
            if (page == "1")
                return BuildAbsolute(String.Format("Product.aspx?ProductID={0}", productId));
            else
                return BuildAbsolute(String.Format("Product.aspx?ProductID={0}&Page={1}", productId, page));
        }
    }
}
